package com.zzzyh.aopdemo.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Slf4j
@Component
@Order(2)
public class TestAop {
    @Pointcut("execution(* com.zzzyh.aopdemo.controller.TestController.*(..))")
    public void pointCut() {
    }

    @Around("pointCut()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("doAround方法执行开始");
        Object ret = joinPoint.proceed();
        log.info("doAround方法执行结束");
        return ret;
    }

    @Before("pointCut()")
    public void doBefore() {
        log.info("doBefore方法执行");
    }

    @After("execution(* com.zzzyh.aopdemo.controller.TestController.*(..))")
    public void dAfter() {
        log.info("After方法执行");
    }

    @AfterReturning("execution(* com.zzzyh.aopdemo.controller.TestController.*(..))")
    public void doAfterReturning() {
        log.info("doAfterReturning方法执行");
    }

    @AfterThrowing("execution(* com.zzzyh.aopdemo.controller.TestController.*(..))")
    public void doAfterThrowing() {
        log.info("doAfterThrowing方法执行");
    }

}
